package com.cskaoyan.market.controller.admin;

import com.cskaoyan.market.db.domain.MarketComment;
import com.cskaoyan.market.service.admin.MarketCommentService;
import com.cskaoyan.market.util.ResponseUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@RequiresAuthentication
@RestController
@RequestMapping("admin/comment")
public class AdminCommentController {

    @Autowired
    MarketCommentService marketCommentService;

    @GetMapping("list")
    public Object list(Integer page, Integer limit, String sort, String order, String userId, String valueId) {

        if (StringUtils.isEmpty(sort)) {
            sort = "add_time";
        }
        if (StringUtils.isEmpty(order)) {
            order = "desc";
        }

        List<MarketComment> list = marketCommentService.list(page, limit, userId, valueId, sort, order);

        return ResponseUtil.okList(list);
    }


    @PostMapping("delete")
    public Object delete(@RequestBody Map<String,Integer> map)  {

        Integer id = map.get("id");
        marketCommentService.delete(id);
        return ResponseUtil.ok();
    }
}
